package system.company.webservice.manager;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import system.company.actor.Manager.Manager_Staff;
import system.company.base.Objects.Object_status;
import system.company.bountry.display_Forms.Application_Form;
import system.company.control.Centers.Operation_Center;

public class InspectApplication_Save extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	Manager_Staff manager_staff = null;
	public InspectApplication_Save() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	private void processRequest(HttpServletRequest request,
			HttpServletResponse response) throws IOException {

		response.setContentType("text/html;charset=gb2312");//------------------------------
		request.setCharacterEncoding("gb2312");
		//response.setContentType("text/html;charset=gb2312");
		//String ID = request.getParameter("ID");
		//String PASSWORD = request.getParameter("password");
		PrintWriter out = response.getWriter();
		response.setStatus(HttpServletResponse.SC_OK);
		HttpSession hsession;
		hsession= request.getSession(true);
		manager_staff=(Manager_Staff)hsession.getAttribute("manager_staff");
		try{
		if(manager_staff==null)
		{
			request.getRequestDispatcher("/Common_Page/Entrance_face.jsp").forward(request, response);
		}
		else
		{

			/*************************/
						hsession.isNew();
						hsession.setAttribute("manager_staff", manager_staff);
						/*********************************/

			if(manager_staff.getStatus()==Object_status.getManager_status())
			{
				Application_Form  form = null;
				form = (Application_Form) hsession.getAttribute("form_application");
				Operation_Center.Save_Application_Form(form);
				
			
				request.getRequestDispatcher("/servlet/InspectApplication_Offer").forward(request, response);
			}
			
				else
				{
					request.getRequestDispatcher("/Common_Page/Entrance_face.jsp").forward(request, response);
				}
			
		}
	}
		catch(Throwable e)
		{
			System.out.println(e);
			try{
				request.getRequestDispatcher("/Common_Page/applicationerror.jsp").forward(request, response);
			}catch(Throwable e2)
			{
				System.out.println(e2);
			}
			
		}
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		processRequest(request,response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		processRequest(request,response);
	}
	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
